/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sg.edu.nus.iss.pacman.form;

import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.StringItem;
import sg.edu.nus.iss.pacman.dao.UserProfile;
import sg.edu.nus.iss.pacman.midlet.PacManMIDlet;
import sg.edu.nus.iss.pacman.util.DateUtils;

/**
 * View the user profile score details.
 * @author daniel, fredy
 */
public class ViewHighScoreUserProfile extends Form implements CommandListener
{
    private Command cmdOK;
    private StringItem profile;
    private static final String TITLE = "User Profile";
    private static final String MALE = "Male";
    private static final String FEMALE = "Female";
    private PacManMIDlet mainApp;
    private UserProfile userProfile;
    
    public ViewHighScoreUserProfile(PacManMIDlet mainApp, UserProfile userProfile)
    {
        super(TITLE);
        this.mainApp = mainApp;
        this.userProfile = userProfile;
        init();
    }

    private void init()
    {
        //Entry Page       
        String text = "Name: " + userProfile.getName() + "\n" +
                "Sex: " + getGender(userProfile.getGender()) + "\n" +
                "Date of Birth: " + DateUtils.convertDateToString(userProfile.getDob()) + "\n" +
                "Email: " + userProfile.getEmail();
        profile = new StringItem("", text);
        append(profile);
        cmdOK = new Command(PacManMIDlet.LABEL_CMD_OK, Command.SCREEN, 1);
        addCommand(cmdOK);
        this.setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d)
    {
        if (cmdOK == c)
        {
            mainApp.displayViewMapHighScore();
        }
    }

    private String getGender(int gender)
    {
        String g = "";
        if (gender == 1)
        {
            g = MALE;
        }
        else
        {
            g = FEMALE;
        }
        return g;
    }
}
